/**
 * Created by Administrator on 2016/11/17.
 */

$(function(){
    var roleId = window.localStorage.getItem("roleId");
    var loginName = window.localStorage.getItem("loginName");
    var roleName = "";
    if(loginName == "" || loginName == null || loginName == "null"){
        window.location.href = getIP()+"login.html";
    }else{
        //获取管理员等级
        var selRole = $.Params.create();
        selRole.addParams("id",roleId);
        selRole.ajax(getIP()+"powerRole/getPowerRoles",function(data){
            if(data.success){
                roleName = data.result[0].roleName;
            }
        })

        //获取左侧菜单
        var selMenu = $.Params.create();
        selMenu.addParams("roleId",roleId);
        selMenu.ajax(getIP()+"powerRoleMenu/getRoleMenu",function(data){
            if(data.success){
                var html = "<div class='user-panel'><div class='pull-left image'>"+
                        "<img src='../img/jiweiyitan.png' class='img-circle' style='width:50px;max-width:50px;height:50px;' alt='User Image'>"+
                        "</div><div class='pull-left info'><p>"+loginName+"</p><a href='#'>"+roleName+"</a></div></div>"+
                        "<ul class='sidebar-menu'><li class='header'>主导航</li>";
                $.each(data.result,function(i,val){
                    if(val.parentId == 0){
                        html+="<li class='treeview'><a href='#'><i class='fa fa-laptop'></i><span>"+val.menuName+"</span>"+
                            "<span class='pull-right-container'><i class='fa fa-angle-left pull-right'></i></span></a><ul class='treeview-menu'>"
                        $.each(data.result,function(j,obj){
                            if(val.id == obj.parentId){
                                html+="<li><a target='right' href='"+obj.url+"'><i class='fa fa-circle-o'></i>"+obj.menuName+"</a></li>"
                            }
                        })
                        html+="</ul></li>";
                    }


                })
                html+="</ul>";
                $("#leftMenu").html(html);
            }
        })
    }

})

function exit(){
    window.localStorage.removeItem("roleId");
    window.localStorage.removeItem("loginName");
    window.location.href = "login.html";
}
